﻿namespace LiSAClient.Core.Viewmodel
{
    using System;
    using System.Collections.Generic;
    using LiSAClient.Core.Interfaces;
    using GalaSoft.MvvmLight;

    public abstract class ContentViewModel : ViewModelBase
    {
        public ISet<string> RequiredPermissions { get; private set; }

        public bool ShowInWindow { get; set; }

        public string Title { get; set; }

        protected IPresenter Presenter { get; set; }

        public ContentViewModel(params string[] requiredPermissions)
        {
            this.ShowInWindow = false;
            this.Title = string.Empty;
            this.RequiredPermissions = new HashSet<string>(requiredPermissions);
            this.Presenter = null;
        }

        public virtual void SetPresenter(IPresenter presenter)
        {
            this.Presenter = presenter;
        }

        public IPresenter GetPresenter()
        {
            return this.Presenter;
        }

        public virtual void OnPresented()
        {
            // Does nothing here.
        }

        public bool IsGuidNullOrEmpty(Guid val)
        {
            if (val == null || val == Guid.Empty)
            {
                return true;
            }

            return false;
        }

        public bool IsGuidNullOrEmpty(Guid? val)
        {
            if (val == null || !val.HasValue || val.Value == Guid.Empty)
            {
                return true;
            }

            return false;
        }

        public bool IsDateTimeNullOrEmpty(DateTime val)
        {
            if (val == null || val == new DateTime(0))
            {
                return true;
            }

            return false;
        }

        public bool IsDateTimeNullOrEmpty(DateTime? val)
        {
            if (val == null || !val.HasValue || val.Value == new DateTime(0))
            {
                return true;
            }

            return false;
        }

        public bool IsTimeSpanNullOrEmpty(TimeSpan val)
        {
            if (val == null || val == new TimeSpan(0))
            {
                return true;
            }

            return false;
        }

        public bool IsTimeSpanNullOrEmpty(TimeSpan? val)
        {
            if (val == null || !val.HasValue || val.Value == new TimeSpan(0))
            {
                return true;
            }

            return false;
        }
    }
}
